<?php
/**
 * Created by PhpStorm.
 * User: FlowerHua
 * Date: 2017/6/22 0022
 * Time: 下午 5:36
 */

class FlowerHuaController extends Admin {

    public $FlowerHua;
    public $linkage;
    public function __construct() {
        parent::__construct();
        $this->linkage = $this->model('linkage');
        $this->FlowerHua = $this->model('FlowerHua');
    }

    public function testAction() {
        if($this->post('submit_del')){
            if ($this->post('del_')=='') {
                $this->adminMsg('请选择你要删除的记录!', url('admin/FlowerHua/'), 2, 1, 1);
            }else {
                $this->adminMsg('多条记录删除成功', url('admin/FlowerHua_moban/'), 3, 1, 1);
            }
        }
        $list = array();
        $list[0] = 1;
        $list[1] = 2;
        $list[2] = 2;
        $list[3] = 2;
        $list[4] = 1;
        $list[5] = 2;
        $list[6] = 2;
        $list[7] = 2;
        $list[8] = 1;
        $list[9] = 2;
        $province = $this->linkage->get_all_list();//地区
        $this->view->assign(array(
            'list'=>$list,
            'province'=>$province,
        ));
        $this->view->display('admin/FlowerHua_list');
    }

    public function indexAction() {
        if ($this->post('submit_del')) {
            if ($this->post('del_')=='') {
                $this->adminMsg('请选择你要删除的记录!', url('admin/FlowerHua/'), 2, 1, 1);
            }else{
                foreach ($_POST as $var=>$value) {
                    if (strpos($var, 'del_')!==false) {
                        $id = (int)str_replace('del_', '', $var);
                        $this->del2Action($id, 1);
                    }
                }
                $this->adminMsg('多条记录删除成功', url('admin/FlowerHua_moban/'), 3, 1, 1);
            }
        }
        $page = (int)$this->get('page') ? (int)$this->get('page') : 1;
        if($this->post('page')){
            $page = (int)$this->post('page');
        }
        $typeid = $this->post('typeid') ? $this->post('typeid') : $this->get('typeid');

        $pagesize = isset($this->site['SITE_ADMIN_PAGESIZE']) && $this->site['SITE_ADMIN_PAGESIZE'] ? $this->site['SITE_ADMIN_PAGESIZE'] : 8;

        $where = "1=1";
        //搜索
        if($typeid){
            $where .= " and typeid=".$typeid;
        }
        $urlparam = array('page' => '{page}','typeid'=>$typeid);
        $order = " id desc";
        $limit = ($page-1)*$pagesize.",$pagesize";
        $list =  $this->FlowerHua->get_admin_list($where,$order ,$limit); //列表
        $total = $this->FlowerHua->get_admin_list($where,$order ,$limit,true); //统计数量
        $pagelist = $this->instance('pagelist');	//加载分页类
        $pagelist->loadconfig();
        $pagelist = $pagelist->total($total)->url(url('admin/FlowerHua_moban/', $urlparam))->num($pagesize)->page($page)->output();
        $province = $this->linkage->get_all_list();//地区
        $this->view->assign(array(
            'province'=>$province,
            'page' => $page,
            'typeid' => $typeid,
            'list' => $list,
            'total' => $total,
            'pagelist' => $pagelist,
        ));
        $this->view->display('admin/FlowerHua_list');
    }

    public function editAction(){
        $id = (int)$this->get('id');
        $list = $this->FlowerHua->get_admin_show($id);
        if($this->post('submit')){
            $data = $this->post('data');
            $this->FlowerHua->set($id,$data);
            $this->adminMsg(lang('success'), url('admin/FlowerHua_moban/edit',array('id'=>$id)), 3, 1, 1);
        }
        $province = $this->linkage->get_all_list();//地区
        $this->view->assign(array(
            'province'=>$province,
            'list' => $list,
        ));
        $this->view->display('admin/FlowerHua_add');
    }

    //直接删除内容
    public function delAction($id=0, $all=0) {
        $id = (int)$this->get('id');
        $this->adminMsg('已删除', url('admin/FlowerHua/index'), 3, 1, 1);die;
        if (!auth::check($this->roleid, 'caidou-del', 'admin')) {
            $this->adminMsg(lang('a-com-0', array('1'=>'FlowerHua_moban', '2'=>'del')));
        }
        $all = $all ? $all : $this->get('all');
        $id = $id ? $id : (int)$this->get('id');
        $this->FlowerHua->del($id);
        $all or $this->adminMsg($this->getCacheCode('caidou') . lang('success'), url('admin/FlowerHua_moban/index'), 3, 1, 1);
    }

    //修改删除的状态
    public function update_delAction() {
        $id = (int)$this->get('id');
        $data = $this->FlowerHua->get_admin_show($id);
        if($data){
            $data['del']=1;
            $this->FlowerHua->del($id);
            $this->adminMsg(lang('success'), url('admin/FlowerHua_moban/index'), 2, 1, 1);
        }else{
            $this->adminMsg(lang('要删除的内容不存在'), url('admin/FlowerHua_moban/index'));
        }
    }

    //修改某一/多 字段
    public function statusAction() {
        $id = (int)$this->get('id');
        $list = $this->FlowerHua->get_admin_show($id);
        if($list){
            $data['status']=2;
            $this->FlowerHua->set($id,$data);
            $this->adminMsg(lang('success'), url('admin/FlowerHua_moban/index'), 2, 1, 1);
        }else{
            $this->adminMsg(lang('要审核的内容不存在'), url('admin/FlowerHua_moban/index'));
        }
    }
    //iFrames
    public function HuaAction(){
        $list = array();
        $list[0] = 1;
        $list[1] = 2;
        $list[2] = 2;
        $list[3] = 2;
        $this->view->assign(array(
            'list' => $list,
        ));
        $this->view->display('admin/FlowerHua_iFrames');
    }

}